INCLUDE_FILE

Otázka od: Viktor Marek

25. 7. 2004 16:09

Zdravim

Help soubor mam zakompilovany v aplikaci v exe a jeho pro jeho spusteni
pouzivam nize uvedene procedury (priklad z tipu na spusteni kalkulacky)
Problem nastane pokud se spusti help, shodi se na listu a chci ukoncit
hlavni aplikaci ShellExecute_AndWait(INCLUDE_FILE);

Jak to zaonacit aby se aplikace mohla ukoncit a soucasne sebou vzala
"INCLUDE_FILE"

Diky za radu a omlouvam se za trochu delsi mail

Viktor Marek
viktor@mbox.vol.cz


procedure TForm1.ExtractRes(ResType, ResName, ResNewName : String);
var
  Res : TResourceStream;
begin
  res := TResourceStream.Create(HInstance, ResName, PChar(ResType));
  try
    Res.SaveToFile(ResNewName);
  finally
    Res.Free;
  end;
end;

procedure TForm1.ShellExecute_AndWait(FileName: String);
var
  exInfo : TShellExecuteInfo;
  ph : DWord;
begin
  FillChar(exInfo, SizeOf(exInfo), 0);
  with exInfo do begin
    cbSize := SizeOf(exInfo);
    fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT;
    Wnd := GetActiveWindow();
    ExInfo.lpVerb := 'open';
    lpFile := PChar(FileName);
    nShow := SW_SHOWNORMAL;
  end;
  if ShellExecuteEx(@exInfo) then begin
    ph := exInfo.HProcess;
  end else begin
    ShowMessage(SysErrorMessage(GetLastError));
    exit;
  end;
  while WaitForSingleObject(ExInfo.hProcess, 50) <> WAIT_OBJECT_0 do
    Application.ProcessMessages;
  CloseHandle(ph);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  INCLUDE_FILE := 'Help.hlp';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ExtractRes('EXEFILE','TESTFILE', INCLUDE_FILE);
  if FileExists(INCLUDE_FILE) then begin
    ShellExecute_AndWait(INCLUDE_FILE);
    DeleteFile(INCLUDE_FILE);
  end;
end;